import time

import pytest
from appium import webdriver
from app_setup import app_init_setting
from appium.options.android import UiAutomator2Options


def login():
    print('开始执行用例...')
    appium_host_url = 'http://127.0.0.1:4723/wd/hub'
    desire_caps_json = app_init_setting()
    # print('desire_caps: '+desire_caps_json)
    if desire_caps_json is not None:
        options = UiAutomator2Options().load_capabilities(desire_caps_json) #这里注意UiAutomator2Options后面一定要加上()
        driver = webdriver.Remote(appium_host_url, options=options)
        contextvars = driver.page_source
        time.sleep(10)
        print(contextvars)
    else:
        raise ValueError('desire_caps must not be None')


def test_login():
    login()

